package com.xltt.watchlauncher3.activity;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.viewpager.widget.ViewPager;

import com.xltt.watchlauncher3.R;
import com.xltt.watchlauncher3.adapter.ViewPagerAdapter;
import com.xltt.watchlauncher3.fragment.BaseFragment;
import com.xltt.watchlauncher3.fragment.ClockDialFragment;
import com.xltt.watchlauncher3.fragment.HeartRateFragment;
import com.xltt.watchlauncher3.fragment.MotionFragment;
import com.xltt.watchlauncher3.fragment.MusicFragment;
import com.xltt.watchlauncher3.fragment.WeatcherFragment;
import com.xltt.watchlauncher3.utils.Logger;
import com.xltt.watchlauncher3.view.MyViewPager;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity {

    private MyViewPager mViewPager;
    private ViewPagerAdapter mViewPagerAdapter;
    private List<BaseFragment> mBaseFragmentList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Logger.d("onCreate()");
        setContentView(R.layout.activity_main);
        initData();
        initViews();
    }

    private void initData(){
        mBaseFragmentList.add(new HeartRateFragment());
        mBaseFragmentList.add(new MotionFragment());
        mBaseFragmentList.add(new ClockDialFragment());
        mBaseFragmentList.add(new WeatcherFragment());
        mBaseFragmentList.add(new MusicFragment());
    }

    private void initViews(){
        mViewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager(),mBaseFragmentList);
        mViewPager = findViewById(R.id.view_pager);
        mViewPager.setAdapter(mViewPagerAdapter);
        mViewPager.setCurrentItem((Integer.MAX_VALUE/2) - 1);
        mViewPager.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                Logger.d("viewpager長按了");
                return true;
            }
        });
//        mViewPager.setOffscreenPageLimit(2);//缓存数量
    }

    /**
     * 设置viewpager是否可左右滑动
     * @param state
     */
    public void setViewPagerSlide(boolean state){
        Logger.d("设置viewpager滑动状态 = " + state);
        if(mViewPager != null){
            mViewPager.setNoScroll(state);
        }
    }

    @Override
    protected void onResume() {
        Logger.d("onResume()");
        super.onResume();
    }

    @Override
    protected void onPause() {
        Logger.d("onPause()");
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        Logger.d("onDestroy()");
        super.onDestroy();
    }
}